<?php
class UploadReportForm extends sfForm
{
  public function configure()
  {
    $this->setWidgets(array(
      //'report_name' => new sfWidgetFormPropelSelect(array('model' => 'WrMember')),
      'report_name' => new sfWidgetFormChoice(array('choices' => array())),
      'report_day'  => new sfWidgetFormJQueryDate(),
      'report_file' => new sfWidgetFormInputFile()
    ));
    $this->widgetSchema->setLabels(array(
      'report_file' => 'Please upload your weekly report'
    ));
    
    $this->widgetSchema->setNameFormat('report[%s]');
 
    $this->setValidators(array(
      'report_name'    => new sfValidatorPropelChoice(array('model' => 'WrMember')),
      'report_day'     => new sfValidatorDate(),
      'report_file'    => new sfValidatorFile(),
    ));
  }
  
  public function populateReportName($day, $member_id = 1)
  {
    $members = WrMemberPeer::getMembersByDay($day, 1);
    if (!$members) return false;
    $choices = array();
    foreach($members as $member) {
      $choices[$member->getId()] = $member->getName();
    }
    $this->getWidget('report_name')->setOption('choices', $choices);
    if (in_array($member_id, $choices)) {
      $this->getWidget('report_name')->setDefault($member_id);
    }
    
    return true;
  }
}